<template>
  <view>
    <view v-if="cart.length>0">
        <!-- 收货地址 -->
        <my-address></my-address>
        <!-- 购物车title -->
        <view class="cart-title">
          <uni-icons type="shop"></uni-icons>
          <text>购物车</text>
        </view>
        <!-- 购物车额列表 -->
        <block v-for="(item, i) in cart" :key="i">
          <my-goods
            :goods="item"
            :showRadio="true"
            :showNum="true"
            @radio-change="radioChangeHandler"
            @num-change="numChangeHandler"
          ></my-goods>
        </block>
        <!-- 购物车结算 -->
        <view class="settle-box">
          <my-settle></my-settle>
        </view>
    </view>
    
    <!-- 空白购物车区域 -->
    <view class="empty-cart" v-else>
      <image src="/static/cart_empty@2x.png" class="empty-img"></image>
      <text class="tip-text">空空如也~</text>
    </view>
  </view>
</template>

<script>
  // 导入设置徽标mixins方法
  import badgeMix from '@/mixins/tabbar-badge.js'
  
  
  import { mapState, mapMutations } from 'vuex'
  
  export default {
    mixins: [badgeMix],
    computed:{
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
        
      };
    },
    onShow() {
      // 设置tabbar徽标
      // this.setBadge()
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount']),
      radioChangeHandler(e){
        console.log('==', e)
        this.updateGoodsState(e)
      },
      
      // 数量改变时触发
      numChangeHandler(e){
        console.log('====',e)
        this.updateGoodsCount(e)
      }
    }
    
  }
</script>

<style lang="scss">
  .cart-title{
    display: flex;
    height: 80rpx;
    align-items: center;
    padding-left: 16rpx;
    border-bottom: 1rpx solid #efefef;
    text {
      margin-left: 16rpx;
    }
  }
  .settle-box {
    padding-bottom: 50px;
  }
  
  .empty-cart {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 150px;
  
    .empty-img {
      width: 90px;
      height: 90px;
    }
  
    .tip-text {
      font-size: 12px;
      color: gray;
      margin-top: 15px;
    }
  }
</style>
